﻿//json字符串去除特殊字符
function stringtojson(s) {
    var newstr = "";
    for (var i = 0, len = s.length; i < len; i++) {
        c = s.charAt(i);
        switch (c) {
            case '\"':
                {
                    newstr += "\\\"";
                    break;
                }
            case '\\':
                {
                    newstr += "\\\\";
                    break;
                }
            case '/':
                {
                    newstr += "\\/";
                    break;
                }
            case '\b':
                {
                    newstr += "\\b";
                    break;
                }
            case '\f':
                {
                    newstr += "\\f";
                    break;
                }
            case '\n':
                {
                    newstr += "\\n";
                    break;
                }
            case '\r':
                {
                    newstr += "\\r";
                    break;
                }
            case '\t':
                {
                    newstr += "\\t";
                    break;
                }
            default:
                {
                    newstr += c;
                }
        }
    }
    return newstr;
}
//获取传值参数
function Request(strName) {
    var strHref = window.document.location.href;
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1);
    var arrTmp = strRight.split("&");
    for (var i = 0; i < arrTmp.length; i++) {
        var arrTemp = arrTmp[i].split("=");
        if (arrTemp[0].toUpperCase() == strName.toUpperCase())
            return arrTemp[1];
    }
    return "";
}

function check_zzs(txt) //正整数
{
    var filter = /^[1-9]\d*$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("只能输入正整数", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}
function check_email(txt) //邮箱验证
{
    var filter = /^[\w.]+@\w{2,5}.com+$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("邮箱格式不对", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}
function check_sz(txt) //数字
{
    var filter = /^\d+$|^\d+[.]?\d+$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("只能输入数字", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}


function check_szAndone(txt) //只能数字并且一位小数
{
    var filter = /^([\+ \-]?(([1-9]\d*)|(0)))([.]\d{0,1})?$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("只能输入数字且1位小数", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}
function check_one(txt) //数字保留1位小数
{
    var filter = /^(\d+\.\d{1,1}|\d+)$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("只能输入数字且1位小数", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}
function check_two(txt) //数字保留2位小数
{
    var filter = /^\d{1,8}(\.\d{1,2})?$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("只能输入数字且2位小数", { icon: 5, anim: 6 });
        txt.value = '';
        //txt.focus();
        return false;
    }
}
function check_sjh(txt) //手机号
{
    var filter = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
    if (filter.test(txt.value)) return true;
    else {
        layer.msg("手机号格式不正确");
        txt.value = '';
        //txt.focus();
        return false;
    }
}
//选择年月
function selectMonth() {
    WdatePicker({ dateFmt: 'yyyy-MM', isShowToday: false, isShowClear: false });
}
//获取url参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}


//填数字的文本框，失去焦点判断是否填了数字
function NaNPointOut(obj) {
    if (isNaN($(obj).val()) && $(obj).val() != "") {
        layer.msg("不支持非数字类型的文本！");
        $(obj).val("").focus();
    }
}
//验证日期（判断结束日期是否大于开始日期）日期格式为YY—MM—DD  
function isStartEndDate(startTime, endTime) {
    if (startTime.length > 0 && endTime.length > 0) {
        var startTmp = startTime.split("-");
        var endTmp = endTime.split("-");
        var sd = new Date(startTmp[0], startTmp[1], startTmp[2]);
        var ed = new Date(endTmp[0], endTmp[1], endTmp[2]);
        if (sd.getTime() > ed.getTime()) {
            return false;
        }
    }
    return true;
}
function mathround(o, len) {
    //浮点数四舍五入 精度
    var rvalue = '&nbsp;';
    var num = 0;
    var _len = '1';
    if (!isNaN(len)) {
        for (var i = 0; i < len; i++) {
            _len += '0';
        }
        _len = parseInt(_len);
    } else { _len = 100000; }
    try {
        return Math.round(parseFloat(o) * _len) / _len;
    } catch (e) { }
    return rvalue;
}
///字符截取
String.format = function () {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
};
function stringCut(string, end) {
    var rvalue = '&nbsp;';
    try {
        if (string.length < end) {
            return string;
        } else {
            rvalue = string.substring(0, end) + "...";
        }
    } catch (e) { return rvalue; }
    return rvalue;
}
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month   
        "d+": this.getDate(),    //day  
        "h+": this.getHours(),   //hour   
        "m+": this.getMinutes(), //minute   
        "s+": this.getSeconds(), //second   
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter  
        "S": this.getMilliseconds() //millisecond 
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
//获取年月日时分秒
function getNowFormatDate2() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
    return currentdate;
}
//获取年月 本月
function getYearAndMonth() {
    var date = new Date();
    var seperator1 = "年";
    var seperator2 = "月";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = year + seperator1 + month + seperator2 ;
    return currentdate;
}
//获取年月-本月
function getYearAndMonth_new() {
    var date = new Date();
    var seperator1 = "年";
    var seperator2 = "月";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = year + '-' + month;
    return currentdate;
}

//获取年月下一个月
function getYearAndMonthAdd1() {
    var date = new Date();
    var seperator1 = "年";
    var seperator2 = "月";
    var year = date.getFullYear();
    var month = date.getMonth() + 2;
    if (month == 13) {
        year = year + 1;
        month = 1;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = year + seperator1 + month + seperator2;
    return currentdate;
}
//获取年月下一个月_新
function getYearAndMonthAdd1_new(resyear, resmonth) {
    //var date = new Date();
    var seperator1 = "年";
    var seperator2 = "月";
    var year = resyear;
    var month = parseInt(resmonth) + 1;
    if (month == 13) {
        year = year + 1;
        month = 1;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate = year + seperator1 + month + seperator2;
    return currentdate;
}
//获取月 下一个月
function getMonthAdd1() {
    var date = new Date();
    var seperator1 = "年";
    var seperator2 = "月";
    var year = date.getFullYear();
    var month = date.getMonth() + 2;
    if (month == 13) {
        year = year + 1;
        month = 1;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var currentdate =  month + seperator2;
    return currentdate;
}
//获取月 下一个月新
function getMonthAdd1_new(resmonth) {
    var month = parseInt(resmonth) + 1;
    if (month == 13) {
        month = 1;
    }
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    return month;
}
//获取月日 本月最后一天
function getMonthLastDay() {
    var date = new Date();
    var month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    var year = date.getFullYear();
   var lastday= getLastDay(year, month);
   return month + "/" + lastday + "日";
}
//获取月日 本月最后一天新
function getMonthLastDay_new(resmonth,resyear) {
   // var date = new Date();
    var month = parseInt(resmonth);
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    //var year = date.getFullYear();
    var lastday = getLastDay(resyear, month);
    return month + "/" + lastday + "日";
}
//获取一个月的最后一天
function getLastDay(year, month) {
    var new_year = year;        //取当前的年份       
    var new_month = month++;    //取下一个月的第一天，方便计算（最后一天不固定）       
    if (month > 12) {                //如果当前大于12月，则年份转到下一年       
        new_month -= 12;            //月份减       
        new_year++;                //年份增       
    }
    var new_date = new Date(new_year, new_month, 1);   // 取当年当月的 下个 月中的第一天  
    // 获取当月最后一天日期            
    return (new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate();
}
// 格式化日期格式为 xxxx-xx-xx
function getFullDate(targetDate) {
    var D, y, m, d;
    if (targetDate) {
        D = new Date(targetDate);
        y = D.getFullYear();
        m = D.getMonth() + 1;
        d = D.getDate();
    } else {
        y = fullYear;
        m = month;
        d = date;
    }
    m = m > 9 ? m : '0' + m;
    d = d > 9 ? d : '0' + d;
    return y + '-' + m + '-' + d;
};
//当前时间
function getNowtDay(d) {
    d = new Date(d);
    return new Date(d).format("yyyy-MM-dd")   //格式为"2019-02-16 00:00:00"
};
//当前加天数
function getAddDay(d,t) {
    d = new Date(d);
    d = +d + (1000 * 60 * 60 * 24) * t;
    d = new Date(d);
    return new Date(d).format("yyyy-MM-dd")   //格式为"2019-02-16 00:00:00"
};
//当前减天数
function getCutDay(d, t) {
    d = new Date(d);
    d = + d - (1000 * 60 * 60 * 24) * t;
    d = new Date(d);
    return new Date(d).format("yyyy-MM-dd")   //格式为"2019-02-16 00:00:00"
};
//获取本月
function getMonth() {
    var date = new Date();
    var month = date.getMonth() + 1;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }

    return month + "月";
}
//获取下月
function getNextMonth() {
    var date = new Date();
    var month = date.getMonth() + 2;
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }

    return month + "月";
}

//获取年月日
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
}
function setAddTime(jsondate, format) {
    var format = typeof (format) == 'string' ? format : 'yyyy-MM-dd hh:mm:ss.S';
    try {
        if (jsondate != null) {
            var rvalue = eval("new " + jsondate.substr(1, jsondate.length - 2)).format(format);
            return rvalue || '&nbsp;';
        } else { return '&nbsp;'; }
    }
    catch (e) {
        return '&nbsp;';
    }
}
//js方法返回值：2015-03-19
 function formatDate(date) {
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? '0' + m : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + m + '-' + d;
 };
 //js方法返回值：2015-03-1912:00
 function formatDateTime(date) {
     var y = date.getFullYear();
     var m = date.getMonth() + 1;
     m = m < 10 ? ('0' + m) : m;
     var d = date.getDate();
     d = d < 10 ? ('0' + d) : d;
     var h = date.getHours();
     var minute = date.getMinutes();
     minute = minute < 10 ? ('0' + minute) : minute;
     return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
 };
function stopBubble(e) {
    // 如果传入了事件对象，那么就是非ie浏览器  
    if (e && e.stopPropagation) {
        //因此它支持W3C的stopPropagation()方法  
        e.stopPropagation();
    } else {
        //否则我们使用ie的方法来取消事件冒泡  
        window.event.cancelBubble = true;
    }
}
/*对象序列化为字符串*/
String.toSerialize = function (obj) {
    var ransferCharForJavascript = function (s) {
        var newStr = s.replace(
        /[\x26\x27\x3C\x3E\x0D\x0A\x22\x2C\x5C\x00]/g,
        function (c) {
            ascii = c.charCodeAt(0)
            return '\\u00' + (ascii < 16 ? '0' + ascii.toString(16) : ascii.toString(16))
        }
        );
        return newStr;
    }
    if (obj == null) {
        return null
    }
    else if (obj.constructor == Array) {
        var builder = [];
        builder.push("[");
        for (var index in obj) {
            if (typeof obj[index] == "function") continue;
            if (index > 0) builder.push(",");
            builder.push(String.toSerialize(obj[index]));
        }
        builder.push("]");
        return builder.join("");
    }
    else if (obj.constructor == Object) {
        var builder = [];
        builder.push("{");
        var index = 0;
        for (var key in obj) {
            if (typeof obj[key] == "function") continue;
            if (index > 0) builder.push(",");
            builder.push(String.format("\"{0}\":{1}", key, String.toSerialize(obj[key])));
            index++;
        }
        builder.push("}");
        return builder.join("");
    }
    else if (obj.constructor == Boolean) {
        return obj.toString();
    }
    else if (obj.constructor == Number) {
        return obj.toString();
    }
    else if (obj.constructor == String) {
        return String.format('"{0}"', ransferCharForJavascript(obj));
    }
    else if (obj.constructor == Date) {
        return String.format('{"__DataType":"Date","__thisue":{0}}', obj.getTime() - (new Date(1970, 0, 1, 0, 0, 0)).getTime());
    }
    else if (this.toString != undefined) {
        return String.toSerialize(obj);
    }
}

//id为空关闭所有
function closewin(id) {
    if (id) {
        $('#modal' + id).modal('hide');
        $('#modal' + id).remove();

    } else {
        $('.formmodal').modal('hide');
        $('.formmodal').remove();
    }
}
function toastrOptions() {
    toastr.options = {
        "closeButton": true,
        "debug": false,
        "positionClass": "toast-top-center",
        "onclick": null,
        "timeOut": "2000"
    }
}
//*******************************消息类*******************************
function messageSuccess(title, msg) {
    toastrOptions();
    toastr['success'](msg, title);
}
function messageInfo(title, msg) {
    toastrOptions();
    toastr['info'](msg, title);
}
function messageWarning(title, msg) {
    toastrOptions();
    toastr['warning'](msg, title);
}
function messageError(title, msg) {
    toastrOptions();
    toastr['error'](msg, title);
}
function messageConfirm(title) {
    bootbox.confirm(title, function (result) {
        alert("Confirm result: " + result);
    });
}
function operate(rvalue, refresh, winid) {
    if (rvalue) {
        top.messageSuccess("提示", "操作成功");
        if (refresh) {
            if (typeof (eval('item_select')) == "function") {
                top.item_select();
            }
        }
    } else {
        top.messageError('错误', '非常抱歉，操作失败，请稍后重试');
    }
    setTimeout(function () { top.closewin(winid); }, 1000);

}
//*******************************同类操作类*******************************
function addactions(o) {
    var dropdownmenu = $('#dropdown-menu');
    var strs = [];
    for (var i = 0; i < o.length; i++) {
        strs.push('<li url="' + o[i].url + '" ' + (o[i].target ? ('target="' + o[i].target + '"') : '') + ' comname="' + o[i].title + '"><a href="###">' + o[i].title + '</a></li>');
        if (o[i].split === true) {
            strs.push('<li class="divider"></li>');
        }
    }
    dropdownmenu.html(strs.join(''));
    if (o.length > 0) { $('#btn-group').show(); } else { $('#btn-group').hide(); }
}
//*******************************操作类*******************************
//删除
function operate_delete(o) {
    var action = { Action: "get", act: 'delete' };
    var url = o.url == undefined ? "ashx/edit.ashx" : o.url;
    for (var attr in o.params) {
        action[attr] = o.params[attr];
    }
    layer.confirm('您确定要删除此条记录吗?', function (r) {
        if (r) {
            $.get(url + "?" + Math.random(),
             action,
             function (data, textStatus) {
                 if (data.flag) {
                     layer.msg('操作成功!');
                     try {
                         if (typeof (item_select) == "function") {
                             item_select();
                         }
                     } catch (e) {
                         layer.msg(e.message);
                     }
                     layer.close(r);
                 }
                 else {
                     layer.msg('非常抱歉，操作失败，请稍后重试');
                 }
                 if (typeof (o.callback) == "function") {
                     o.callback(data.flag);
                 }
             }
        )
        }
    });
}

//自定义-提示(修改密码)
function operate_updatepwd(o) {
    var action = { Action: "get", act: '123' };
    var url = o.url == undefined ? "ashx/list.ashx" : o.url;
    for (var attr in o.params) {
        action[attr] = o.params[attr];
    }
    layer.confirm(o.txmessage, function (r) {
        if (r) {
            $.get(url + "?" + Math.random(),
             action,
             function (data, textStatus) {
                 if (data.flag) {
                     layer.msg('修改成功!');
                     try {
                         if (typeof (item_select) == "function") {
                             item_select();
                         }
                     } catch (e) {
                         layer.msg(e.message);
                     }
                     clearCookie();
                     window.location.href = "login.html";
                 }
                 else {
                     layer.msg(o.fhmessage);
                 }
                 if (typeof (o.callback) == "function") {
                     o.callback(data.flag);
                 }
             }
        )
        }
    });
}

//自定义-提示
function operate_zdy(o) {
    var action = { Action: "get", act: '123' };
    var url = o.url == undefined ? "ashx/list.ashx" : o.url;
    for (var attr in o.params) {
        action[attr] = o.params[attr];
    }
    layer.confirm(o.txmessage, function (r) {
        if (r) {
            $.get(url + "?" + Math.random(),
             action,
             function (data, textStatus) {
                 if (data.flag) {
                     layer.msg('操作成功!');
                     try {
                         if (typeof (item_select) == "function") {
                             item_select();
                         }
                     } catch (e) {
                         layer.msg(e.message);
                     }
                     layer.close(r);
                 }
                 else {
                     layer.msg(o.fhmessage);
                 }
                 if (typeof (o.callback) == "function") {
                     o.callback(data.flag);
                 }
             }
        )
        }
    });
}


//结转提示
function operate_zdy_jz(o) {
    var action = { Action: "get", act: '123' };
    var url = o.url == undefined ? "ashx/list.ashx" : o.url;
    for (var attr in o.params) {
        action[attr] = o.params[attr];
    }
    layer.confirm(o.txmessage, function (r) {
        if (r) {
            $.get(url + "?" + Math.random(),
             action,
             function (data, textStatus) {
                 if (data.flag) {
                     $("#jh_zjlps").val(data.jzsl);
                     //layer.msg('操作成功!共结转'+data.jzsl+'条');
                     try {
                         if (typeof (item_select) == "function") {
                             item_select();
                         }
                     } catch (e) {
                         layer.msg(e.message);
                     }
                     layer.close(r);
                 }
                 else {
                     layer.msg(o.fhmessage);
                     $("#jh_zjlps").val("");
                 }
                 if (typeof (o.callback) == "function") {
                     o.callback(data.flag);
                 }
             }
        )
        }
    });
}



function operate_delete_zdy(o) {
    var action = { Action: "get", act: 'delete' };
    var url = o.url == undefined ? "ashx/edit.ashx" : o.url;
    for (var attr in o.params) {
        action[attr] = o.params[attr];
    }
    layer.confirm('您确定要删除此条记录吗?', function (r) {
        if (r) {
            $.get(url + "?" + Math.random(),
             action,
             function (data, textStatus) {
                 debugger
                 if (data.flag) {
                     layer.msg('操作成功!');
                     try {
                         if (typeof (item_select) == "function") {
                             item_select();
                         }
                     } catch (e) {
                         layer.msg(e.message);
                     }
                     layer.close(r);
                 }
                 else {
                     layer.msg(o.message);
                 }
                 if (typeof (o.callback) == "function") {
                     o.callback(data.flag);
                 }
             }
        )
        }
    });
}
//获取下拉_是否
function get_selectisnew(selectid, getselectvalue) {
                $("#" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
}
//获取下拉_选中值-二层
function get_selected(type, selectid, getselectvalue) {
    $.ajax({
        url: "../../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),     //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#" + selectid + "").html("<option value=''></option> " + optionstring);
                $("#" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}


//获取下拉通用-一层-通用
function get_selectall_ty(type, selectid) {
    $.ajax({

        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),    //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        async: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#" + selectid + "").html("<option value='10'></option> " + optionstring);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉_选中值-通用
function get_selected_ty(type, selectid, getselectvalue) {
    $.ajax({
        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),     //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#" + selectid + "").html("<option value='10'></option> " + optionstring);
                $("#" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉通用-一层-任务库用
function get_selectall1(type, selectid) {
    $.ajax({

        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),    //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        async: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#rwk_status_" + selectid + "").html("<option value='10'></option> " + optionstring);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉_选中值-任务库用
function get_selected2(type, selectid, getselectvalue) {
    $.ajax({
        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),     //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#rwk_status_" + selectid + "").html("<option value='10'></option> " + optionstring);
                $("#rwk_status_" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉_选中值-事项计划用
function get_selected_sxhy(type, selectid, getselectvalue) {
    $.ajax({
        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),     //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#sxhy_sxorhy_" + selectid + "").html("<option value=''></option> " + optionstring);
                $("#sxhy_sxorhy_" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}

//获取下拉_选中值-计划用
function get_selected_jh(type, selectid, getselectvalue) {
    $.ajax({
        url: "../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),     //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#jh_isnew_" + selectid + "").html("<option value=''></option> " + optionstring);
                $("#jh_isnew_" + selectid + " option[value='" + getselectvalue + "']").attr("selected", true);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}

//获取下拉通用-二层
function get_selectall(type,selectid) {
    $.ajax({

        url: "../../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),    //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        async: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#"+selectid+"").html("<option value=''></option> " + optionstring);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉通用-结转用
function get_select_jz(type, selectid) {
    $.ajax({

        url: "../../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),    //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        async: true,
        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += "<option value=\"" + jsonObj.item[j].ID + "\" >" + jsonObj.item[j].VALUE + "</option>";
                }
                $("#" + selectid + "").html("<option value='-1'>全部</option> " + optionstring);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
//获取下拉(复选框)通用
function get_selectandcheck(type, selectid) {
    $.ajax({

        url: "../../ashx/get_select.ashx?type=" + type + "&r=" + Math.random(),    //后台webservice里的方法名称  
        type: "post",
        dataType: "json",
        contentType: "application/json",
        traditional: true,
        async: true,

        success: function (data) {
            for (var i in data) {
                var jsonObj = data;
                var optionstring = "";
                for (var j = 0; j < jsonObj.item.length; j++) {
                    optionstring += " <label><input type='checkbox' onclick='input_status(\"" + jsonObj.item[j].VALUE + "\")' value=\"" + jsonObj.item[j].ID + "\" /> " + jsonObj.item[j].VALUE + "</label>";

                }
                $("#" + selectid + "").html("<label class='all'><input  type='checkbox' id='selectall' onclick='selectAll()'/> 全部</label>" + optionstring);
            }
        },
        error: function (msg) {
            alert("出错了！");
        }
    });
}
///设置cookie--在用
//function setCookie(NameOfCookie, value, expiredays) {
//    //@参数:三个变量用来设置新的cookie:
//    //cookie的名称,存储的Cookie值,
//    // 以及Cookie过期的时间.
//    // 这几行是把天数转换为合法的日期
//    var ExpireDate = new Date();
//    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
//    // 下面这行是用来存储cookie的,只需简单的为"document.cookie"赋值即可.
//    // 注意日期通过toGMTstring()函数被转换成了GMT时间。
//    document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
//}
//取得cookie-在用  
//function getCookie(name) {
//    var nameEQ = name + "=";
//    var ca = document.cookie.split(';');    //把cookie分割成组    
//    for (var i = 0; i < ca.length; i++) {
//        var c = ca[i];                      //取得字符串    
//        while (c.charAt(0) == ' ') {          //判断一下字符串有没有前导空格    
//            c = c.substring(1, c.length);      //有的话，从第二位开始取    
//        }
//        if (c.indexOf(nameEQ) == 0) {       //如果含有我们要的name    
//            return unescape(c.substring(nameEQ.length, c.length));    //解码并截取我们要值    
//        }
//    }
//    return false;
//}
///删除cookie
function delCookie(NameOfCookie) {
    // 该函数检查下cookie是否设置，如果设置了则将过期时间调到过去的时间;
    //剩下就交给操作系统适当时间清理cookie啦
    if (getCookie(NameOfCookie)) {
        document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
function deleteCookie(name) {
    var date = new Date();
    date.setTime(date.getTime() - 10000);
    document.cookie = name + "=v; expires=" + date.toGMTString();
}
function clearCookie(name) {
    setCookie(name, "", -1);
}
//清除所有cookie
function clearCookie() {
    var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
    if (keys) {
        for (var i = keys.length; i--;)
            document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
    }
}